package com.xinzhi.text;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class BookInset {
    public void addbook(){
        try {
            //加载驱动
            Class.forName("com.mysql.jdbc.Driver");
            //通过DriverManager获得连接
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/sy","root","123456");
            //通过连接获得statement对象
            Statement stat = conn.createStatement();
            //创建sql语句
            String sql = "insert into book values(5,'恶搞','ss','sjek','sjsk','20')";
            //stat对象执行sql语句 //count受影响行数
            int count = stat.executeUpdate(sql);
            //count大于0成功，否则失败
            if(count>0){
                System.out.println("成功");
            }else{
                System.out.println("失败");
            }


        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }

}
